package com.fuyao.cloud.common.data.mybatis;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;

/**
 * @author lyhil
 * @date 2021年12月22日
 */
class AddSearchCondition {

	@SuppressWarnings({})
	static void eq(QueryWrapper queryWrapper, boolean condition, String mappingField, Object value) {
		queryWrapper.eq(condition, mappingField, value);
	}

	static void gt(QueryWrapper queryWrapper, boolean condition, String mappingField, Object value) {
		queryWrapper.gt(condition, mappingField, value);
	}

	static void lt(QueryWrapper queryWrapper, boolean condition, String mappingField, Object value) {
		queryWrapper.lt(condition, mappingField, value);
	}

	static void ge(QueryWrapper queryWrapper, boolean condition, String mappingField, Object value) {
		queryWrapper.ge(condition, mappingField, value);
	}

	static void le(QueryWrapper queryWrapper, boolean condition, String mappingField, Object value) {
		queryWrapper.le(condition, mappingField, value);
	}

	static void like(QueryWrapper queryWrapper, boolean condition, String mappingField, Object value) {
		queryWrapper.like(condition, mappingField, value);
	}

	static void likeLeft(QueryWrapper queryWrapper, boolean condition, String mappingField, Object value) {
		queryWrapper.likeLeft(condition, mappingField, value);
	}

	static void likeRight(QueryWrapper queryWrapper, boolean condition, String mappingField, Object value) {
		queryWrapper.likeRight(condition, mappingField, value);
	}

	static void notLike(QueryWrapper queryWrapper, boolean condition, String mappingField, Object value) {
		queryWrapper.notLike(condition, mappingField, value);
	}

	static void in(QueryWrapper queryWrapper, boolean condition, String mappingField, Object value) {
		queryWrapper.in(condition, mappingField, StrUtil.split(String.valueOf(value), ','));
	}

	static void notIn(QueryWrapper queryWrapper, boolean condition, String mappingField, Object value) {
		queryWrapper.notIn(condition, mappingField, StrUtil.split(String.valueOf(value), ','));
	}

	static void between(QueryWrapper queryWrapper, boolean condition, String mappingFiled, Object value) {
		if (value instanceof List) {
			List conditions = (List) value;
			Object startValue = CollUtil.getFirst(conditions);
			Object endValue = (CollUtil.isNotEmpty(conditions) && conditions.size() > 1) ? CollUtil.getLast(conditions) : null;
			queryWrapper.between(CollUtil.isNotEmpty(conditions), mappingFiled, startValue, endValue);
		}
	}
}
